package com.ruoyi.web.controller.record;

import java.util.List;

import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.record.domain.WordStudyStepStudent;
import com.ruoyi.record.service.IWordStudyStepStudentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 单词学习任务Controller
 * 
 * @author ruoyi
 * @date 2025-08-11
 */
@RestController
@RequestMapping("/record/taskAddstudent")
public class WordStudyStepStudentController extends BaseController
{
    @Autowired
    private IWordStudyStepStudentService wordStudyStepStudentService;


    /**
     * 查询单词学习任务列表
     */
//    @PreAuthorize("@ss.hasPermi('record:taskAddstudent:list')")
    @GetMapping("/list")
    public TableDataInfo list(WordStudyStepStudent wordStudyStepStudent)
    {
        startPage();
        List<WordStudyStepStudent> list = wordStudyStepStudentService.selectWordStudyStepStudentList(wordStudyStepStudent);
        return getDataTable(list);
    }

    /**
     * 导出单词学习任务列表
     */
//    @PreAuthorize("@ss.hasPermi('record:taskAddstudent:export')")
    @Log(title = "单词学习任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WordStudyStepStudent wordStudyStepStudent)
    {
        List<WordStudyStepStudent> list = wordStudyStepStudentService.selectWordStudyStepStudentList(wordStudyStepStudent);
        ExcelUtil<WordStudyStepStudent> util = new ExcelUtil<WordStudyStepStudent>(WordStudyStepStudent.class);
        util.exportExcel(response, list, "单词学习任务数据");
    }

    /**
     * 获取单词学习任务详细信息
     */
//    @PreAuthorize("@ss.hasPermi('record:taskAddstudent:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(wordStudyStepStudentService.selectWordStudyStepStudentById(id));
    }

    @GetMapping("/myList")
    public AjaxResult getMyListAll(){
        Long userId = getUserId();
        List<WordStudyStepStudent> list = wordStudyStepStudentService.getMyStudyList(userId);
        return AjaxResult.success(list);
    }

    @GetMapping("/myList/{id}")
    public AjaxResult getMyList(@PathVariable("id") Long id){

        Long userId = getUserId();
        List<WordStudyStepStudent> list = wordStudyStepStudentService.getMyStudyList(id, userId);
        return AjaxResult.success(list);
    }

    @GetMapping("/receive/{id}")
    public AjaxResult receiveMyStudy(@PathVariable("id") Long id){
        wordStudyStepStudentService.receiveMyStudy(id);
        return AjaxResult.success();
    }

    /**
     * 新增单词学习任务
     */
//    @PreAuthorize("@ss.hasPermi('record:taskAddstudent:add')")
    @Log(title = "单词学习任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WordStudyStepStudent wordStudyStepStudent)
    {
        String student = wordStudyStepStudentService.insertWordStudyStepStudent(wordStudyStepStudent);
        return AjaxResult.success(student);
    }

    /**
     * 修改单词学习任务
     */
//    @PreAuthorize("@ss.hasPermi('record:taskAddstudent:edit')")
    @Log(title = "单词学习任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WordStudyStepStudent wordStudyStepStudent)
    {
        return toAjax(wordStudyStepStudentService.updateWordStudyStepStudent(wordStudyStepStudent));
    }

    /**
     * 删除单词学习任务
     */
//    @PreAuthorize("@ss.hasPermi('record:taskAddstudent:remove')")
    @Log(title = "单词学习任务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wordStudyStepStudentService.deleteWordStudyStepStudentByIds(ids));
    }
}
